* PREPARE CMP *
* For use in the CSES DO-file

* Data
* CMP data available from https://manifesto-project.wzb.eu/
use "MPDataset_MPDS2018b_stata14", clear
gen year = year(edate)

* Salience
gen sal_cul = (per501+per502+per503+per601+per602+per603+per604+per605+per607+per608)
gen sal_cul_old = (per603+per604+per605)
gen sal_cul_new = (per601+per602+per607+per608+per705)
gen sal_eco = (per401+per402+per403+per404+per405+per406+per407+per408+per409+per410+per412+per413+per414+per415)

* PRR
recode party (11710 12951 13720 14820 21914 22430 22720 22722 22730 31720 32720 34720 41953 42420 42710 43810 51951=1) (nonmissing=0), gen(PRR) 
gen mn_PRR = pervote*PRR

* ENOP
recode absseat (0=0) (nonmissing=1), gen(atleastoneseat)
gen seats_sq = (absseat/totseats)^2 if atleastoneseat==1
bys country edate: egen ENOP_inv = sum(seats_sq) if atleastoneseat==1
gen ENOP = 1/ENOP_inv if atleastoneseat==1

* Polarization
gen leftright = (rile+100)/20
gen seatshare = absseat/totseats
gen wgt_leftright = leftright*seatshare
bys country edate: egen mn_leftright = sum(wgt_leftright)
bys country edate: egen sd_leftright2 = sd(wgt_leftright)

* Aggregate & save
collapse (mean) sal_cul* sal_eco total mn_PRR rile ENOP mn_leftright sd_leftright, by(year country)
save "cmp_recoded.dta", replace

